package com.wdciti.sccp.iot.springvertx.configure;

import com.wdciti.sccp.iot.common.aio.AioEngine;
import com.wdciti.sccp.iot.common.endpoint.UseEndpointAspect;
import com.wdciti.sccp.iot.springvertx.VertxInSpring;
import com.wdciti.sccp.iot.springvertx.annotation.ConditionalOnVertxEnabled;
import com.wdciti.sccp.iot.springvertx.factory.EndpointBeanVerticleFactory;
import com.wdciti.sccp.iot.springvertx.factory.SpringBeanVerticleFactory;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author by early
 */
@AutoConfigureOrder(100)
@Configuration(proxyBeanMethods = false)
public class SpringVertxAutoConfiguration {

    @Bean
    VertxOptionsConfiguration vertxOptionConfiguration() {
        return new VertxOptionsConfiguration();
    }

    @Bean
    VerticleExclude verticleExclude() {
        return new VerticleExclude();
    }

    @Bean
    UseEndpointAspect useEndpointAspect() {
        return new UseEndpointAspect();
    }

    @Bean
    @ConditionalOnVertxEnabled
    @ConditionalOnMissingBean(AioEngine.class)
    AioEngine springVertxManager(VertxOptionsConfiguration configuration) {
        return new VertxInSpring(configuration);
    }

    @Bean
    @ConditionalOnBean(AioEngine.class)
    SpringBeanVerticleFactory springBeanVerticleFactory() {
        return new SpringBeanVerticleFactory();
    }

    @Bean
    @ConditionalOnBean(AioEngine.class)
    EndpointBeanVerticleFactory endpointBeanVerticleFactory() {
        return new EndpointBeanVerticleFactory();
    }


}
